home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dflat2.zip / VIDEO.C < prev    next >
Text File  |  1991-02-18  |  4KB  |  133 lines

  1. /* --------------------- video.c -------------------- */
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #include <string.h>
  5. #include <conio.h>
  6. #include "dflat.h"
  7.  
  8. static unsigned video_address;
  9. /* -- read a rectangle of video memory into a save buffer -- */
  10. void getvideo(RECT rc, void far *bf)
  11. {
  12.     int ht = RectBottom(rc)-RectTop(rc)+1;
  13.     int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
  14.     unsigned vadr = vad(RectLeft(rc), RectTop(rc));
  15.     hide_mousecursor();
  16.     while (ht--)    {
  17.         movedata(video_address, vadr, FP_SEG(bf),
  18.                 FP_OFF(bf), bytes_row);
  19.         vadr += 160;
  20.         (char far *)bf += bytes_row;
  21.     }
  22.     show_mousecursor();
  23. }
  24.  
  25. /* -- write a rectangle of video memory from a save buffer -- */
  26. void storevideo(RECT rc, void far *bf)
  27. {
  28.     int ht = RectBottom(rc)-RectTop(rc)+1;
  29.     int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
  30.     unsigned vadr = vad(RectLeft(rc), RectTop(rc));
  31.     hide_mousecursor();
  32.     while (ht--)    {
  33.         movedata(FP_SEG(bf), FP_OFF(bf), video_address,
  34.                 vadr, bytes_row);
  35.         vadr += 160;
  36.         (char far *)bf += bytes_row;
  37.     }
  38.     show_mousecursor();
  39. }
  40.  
  41. /* -------- read a character of video memory ------- */
  42. int GetVideoChar(int x, int y)
  43. {
  44.     int c;
  45.     hide_mousecursor();
  46.     c = peek(video_address, vad(x,y));
  47.     show_mousecursor();
  48.     return c;
  49. }
  50.  
  51. /* -------- write a character of video memory ------- */
  52. void PutVideoChar(int x, int y, int c)
  53. {
  54.     if (x < SCREENWIDTH && y < SCREENHEIGHT)    {
  55.         hide_mousecursor();
  56.         poke(video_address, vad(x,y), c);
  57.         show_mousecursor();
  58.     }
  59. }
  60.  
  61. /* -------- write a character to a window ------- */
  62. void wputch(WINDOW wnd, int c, int x, int y)
  63. {
  64.     int x1 = GetClientLeft(wnd)+x;
  65.     int y1 = GetClientTop(wnd)+y;
  66.     if (x1 < SCREENWIDTH && y1 < SCREENHEIGHT)    {
  67.         hide_mousecursor();
  68.         poke(video_address,
  69.             vad(x1,y1),(c & 255) |
  70.                 (clr(foreground, background) << 8));
  71.         show_mousecursor();
  72.     }
  73. }
  74.  
  75. /* ------- write a string to a window ---------- */
  76. void wputs(WINDOW wnd, void *s, int x, int y)
  77. {
  78.     int x1 = GetLeft(wnd)+x;
  79.     int y1 = GetTop(wnd)+y;
  80.     if (x1 < SCREENWIDTH && y1 < SCREENHEIGHT)    {
  81.         int fg = foreground;
  82.         int bg = background;
  83.         unsigned char *str = s;
  84.         char ss[200];
  85.         int ln[SCREENWIDTH];
  86.         int *cp1 = ln;
  87.         int len;
  88.         strncpy(ss, s, 199);
  89.         ss[199] = '\0';
  90.         clipline(wnd, x, ss);
  91.         str = (unsigned char *) ss;
  92.         hide_mousecursor();
  93.         while (*str)    {
  94.             if (*str == CHANGECOLOR)    {
  95.                 str++;
  96.                 foreground = (*str++) & 0x7f;
  97.                 background = (*str++) & 0x7f;
  98.                 continue;
  99.             }
  100.             if (*str == RESETCOLOR)    {
  101.                 foreground = fg;
  102.                 background = bg;
  103.                 str++;
  104.                 continue;
  105.             }
  106.             *cp1++ = (*str & 255) |
  107.                 (clr(foreground, background) << 8);
  108.             str++;
  109.         }
  110.         foreground = fg;
  111.         background = bg;
  112.         len = (int)(cp1-ln);
  113.         if (x1+len > SCREENWIDTH)
  114.             len = SCREENWIDTH-x1;
  115.         movedata(FP_SEG(ln), FP_OFF(ln), video_address,
  116.             vad(x1,y1), len*2);
  117.         show_mousecursor();
  118.     }
  119. }
  120.  
  121. /* --------- get the current video mode -------- */
  122. void get_videomode(void)
  123. {
  124.     videomode();
  125.     /* ---- Monochrome Display Adaptor or text mode ---- */
  126.     if (ismono())
  127.         video_address = 0xb000;
  128.     else
  129.         /* ------ Text mode -------- */
  130.         video_address = 0xb800 + video_page;
  131. }
  132.  
  133.